package com.gwnet.rider.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gwnet.common.core.domain.ResponseResult;
import com.gwnet.common.core.exception.base.BaseException;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.rider.domain.RiderWithdrawCash;
import com.gwnet.rider.domain.bo.ApplyWithdrawalBO;
import com.gwnet.rider.domain.bo.RiderWithdrawCashPageBO;
import com.gwnet.rider.service.RiderWithdrawCashService;
import com.gwnet.system.api.model.LoginUser;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 骑手提现申请表 前端控制器
 * </p>
 *
 * @author WangLiang
 * @since 2024-08-06
 */
@RestController
@RequestMapping("/riderWithdrawCash")
public class RiderWithdrawCashController {

    private final RiderWithdrawCashService riderWithdrawCashService;

    public RiderWithdrawCashController(RiderWithdrawCashService riderWithdrawCashService) {
        this.riderWithdrawCashService = riderWithdrawCashService;
    }

    /**
     * 骑手申请提现
     * @param applyWithdrawalBO
     * @return
     */
    @PostMapping("/applyWithdrawal")
    public ResponseResult<Boolean> applyWithdrawal(@RequestBody ApplyWithdrawalBO applyWithdrawalBO){
        Boolean flag = riderWithdrawCashService.applyWithdrawal(applyWithdrawalBO);
        return ResponseResult.success(flag);
    }


    /**
     * 分页查询提现历史记录
     * @param pageBO
     * @return
     */
    @PostMapping("/page")
    public ResponseResult<IPage<RiderWithdrawCash>> page(@RequestBody RiderWithdrawCashPageBO pageBO){
        IPage<RiderWithdrawCash> page = riderWithdrawCashService.page(pageBO);
        return ResponseResult.success(page);
    }

    /**
     * 查看提现记录详情
     * @param riderWithdrawCash
     * @return
     */
    @PostMapping("/view")
    public ResponseResult<RiderWithdrawCash> view(@RequestBody RiderWithdrawCash riderWithdrawCash){
        LoginUser loginUser = LoginHelper.getLoginUser();
        RiderWithdrawCash cash = riderWithdrawCashService.getById(riderWithdrawCash.getCashId());
        if(!cash.getRiderId().equals(loginUser.getUserId())){
            // 通过技术手段看别人的提现记录，提示错误
            throw new BaseException("请勿通过其他形式查看他人提现记录");
        }
        return ResponseResult.success(cash);
    }


















}

